<html><head>
	<meta content="text/html; charset=utf-8" http-equiv="Content-Type"> 
	<script src='<?=_P("application/views/scripts/jquery-1.5.1.js")?>'></script>
	<style>
	</style>
</head>
<body>
<script src="<?=_U("script/models/db")?>"></script>

<?php 
if(!function_exists('set_value'))
{
	function set_value($name,$default=null)
	{
		if(isset($_POST[$name]))
		{
			return $_POST[$name];
		}
		else {
			return $default;
		}
	}
}

if(!function_exists('form_error1'))
{
	function form_error1($error,$name,$begin_tag="",$end_tag="")
	{
		if(isset($error[$name]))
		{
			return $begin_tag.$error[$name].$end_tag;
		}
	}
}
?>
<script src="<?=_U("script/libraries/web_fetcher")?>"></script>
<script>

$(document).ready(function(){

	$('#btn_collection').click(function(){
		var params = {};
		params.url = $('#url').val();
		var start_val = $('#start').val();
		start_val = start_val.replace(/\"/g,'\\\"');
		start_val = start_val.replace(/\'/g,"\\\'"); 
		params.start = start_val;
		var end_val = $('#end').val();
		end_val = end_val.replace(/\"/g,'\\\"');
		end_val = end_val.replace(/\'/g,"\\\'");
		params.end = end_val;
		var link_parse_regular_val = $('#link_parse_regular').val();
		link_parse_regular_val = link_parse_regular_val.replace(/\"/g,'\\\"');
		link_parse_regular_val = link_parse_regular_val.replace(/\'/g,"\\\'");
		params.link_parse_regular = link_parse_regular_val;
		web_fetcher.parse_list_links(params,function(data){
			var c = $('<div></div>');
			$('#right').append(c);
			//data.length 
			for(jr_i=0;jr_i<data.length;jr_i++)
			{
				var jr_params = {};
				var link = data[jr_i] ;
				jr_params.url = link;
				//alert('abc'); 
				var page_charset_val = $('#page_charset').val();
				page_charset_val = page_charset_val.replace(/\"/g,'\\\"');
				page_charset_val = page_charset_val.replace(/\'/g,"\\\'");
				jr_params.page_charset = page_charset_val;
				//alert(page_charset_val);
				var page_start_val = $('#page_start').val();
				page_start_val = page_start_val.replace(/\"/g,'\\\"');
				page_start_val = page_start_val.replace(/\'/g,"\\\'");
				jr_params.page_start = page_start_val;
				//alert(page_start_val);
				var page_end_val = $('#page_end').val();
				page_end_val = page_end_val.replace(/\"/g,'\\\"');
				page_end_val = page_end_val.replace(/\'/g,"\\\'");
				jr_params.page_end = page_end_val;
				var title_regular_val = $('#title_regular').val();
				title_regular_val = title_regular_val.replace(/\"/g,'\\\"');
				title_regular_val = title_regular_val.replace(/\'/g,"\\\'");
				jr_params.title_regular = title_regular_val;
				var datetime_regular_val = $('#datetime_regular').val();
				datetime_regular_val = datetime_regular_val.replace(/\"/g,'\\\"');
				datetime_regular_val = datetime_regular_val.replace(/\'/g,"\\\'");
				jr_params.datetime_regular = datetime_regular_val;
				var from_regular_val = $('#from_regular').val();
				from_regular_val = from_regular_val.replace(/\"/g,'\\\"');
				from_regular_val = from_regular_val.replace(/\'/g,"\\\'");
				jr_params.from_regular = from_regular_val;
				var content_regular_val = $('#content_regular').val();
				content_regular_val = content_regular_val.replace(/\"/g,'\\\"');
				content_regular_val = content_regular_val.replace(/\'/g,"\\\'");
				jr_params.content_regular = content_regular_val;
				var author_regular_val = $('#author_regular').val();
				author_regular_val = author_regular_val.replace(/\"/g,'\\\"');
				author_regular_val = author_regular_val.replace(/\'/g,"\\\'");
				jr_params.author_regular = author_regular_val;
				var page_class_val = $('#page_class').val();
				jr_params.page_class = page_class_val;
				//alert(jr_params.page_class);return; 
				web_fetcher.parse_page(jr_params,function(data){
					//alert(data.title);return;
					//alert(data.page_class);return;
					//var d = {class_id:data.page_class,title:data.title,contribute_time:data.datetime,content:data.content,author:data.author};
					//alert(d.title);return;
					//c.append($("<div>" + d.title + " " + d.contribute_time + " " + d.author + "</div>"));
					//alert(d.title);
				
					var new_content = data.content;
					new_content = new_content.replace(/\"/g,'\\\"');
					new_content = new_content.replace(/\'/g,"\\\'");  
					new_content = new_content.replace(/\r\n/g,""); 
					new_content = new_content.replace(/\n/g,"");  
					new_content = new_content.replace(/\r/g,"");   
					new_content = new_content.replace(/\t/g,"");
					// data.content = "bcde";
					data.content = new_content;
					//alert(new_content);return;
					// alert(data.content);
					//db.insert('pages',{class_id:data.page_class,title:data.title,contribute_time:data.datetime,author:data.author},function(data1){
					db.insert('pages',data,function(data1){
						//alert(new_content);return;
						if(data1.result)
						{
							//alert(data.title);return;
							c.append($("<div>" + data.title + " 插入成功  " + "</div>"));
							
							
						}
						else
						{
							alert(data1) ;
						}
					});
				});
			}
			
		});
	});
});
	
</script>

<form action="<?=$_SERVER['REQUEST_URI']?>" method="post"> 
<table><tr><td>
<div id="normal" class="tab_body" style="display: block;">
	<table width="100%"><tbody>
		<tr class='form_line'>
			<td class='title'>采集器名</td>
			<td class='content'>
				<input name='p_title' size="48" value='<?=set_value('p_title', $title)?>' type='text' />  
				<?=form_error1($error,'p_title', '<font color="red">', '</font>')?>  
			</td>
		</tr>
		<tr class="form_line">
			<td class="title">待采集网址</td>
			<td class="content">
				<input name="p_url" id="url" size="48" type="text" value='<?=set_value('p_url', $url)?>' />
				<?=form_error1($error,'p_url', '<font color="red">', '</font>')?> 
			</td>
		</tr>
		
		<tr class="form_line">
			<td class="title">列表页起始位置</td>
			<td class="content">
				<textarea name="p_start" id="start" style="width:80%;height:40px;"><?=set_value('p_start', $start)?></textarea>  
				<?=form_error1($error,'p_start', '<font color="red">', '</font>')?> 
			</td>
		</tr>
		<tr class="form_line">
			<td class="title">列表页结束位置</td>
			<td class="content">
				<textarea name="p_end" id="end" style="width:80%;height:40px;"><?=set_value('p_end', $end)?></textarea>  
				<?=form_error1($error,'p_end', '<font color="red">', '</font>')?>
			</td>
		</tr>
		<tr class="form_line">
			<td class="title">列表页文章链接规则</td>
			<td class="content">
				<textarea name="p_link_parse_regular" id="link_parse_regular" style="width:80%;height:40px;"><?=set_value('p_link_parse_regular', $link_parse_regular)?></textarea>  
				<?=form_error1($error,'p_link_parse_regular', '<font color="red">', '</font>')?>
			</td>
		</tr>
		<tr class="form_line">
			<td class="title">页面文字编码规则</td>
			<td class="content">
				<textarea name="p_page_charset" id="page_charset" style="width:80%;height:40px;"><?=set_value('p_page_charset', $page_charset)?></textarea>  
				<?=form_error1($error,'p_page_charset', '<font color="red">', '</font>')?>
			</td>
		</tr>
		<tr class="form_line">
			<td class="title">页面起始位置</td>
			<td class="content">
				<textarea name="p_page_start" id="page_start" style="width:80%;height:40px;"><?=set_value('p_page_start', $page_start)?></textarea>  
				<?=form_error1($error,'p_page_start', '<font color="red">', '</font>')?>
			</td>
		</tr>
		<tr class="form_line">
			<td class="title">页面结束位置</td>
			<td class="content">
				<textarea name="p_page_end" id="page_end" style="width:80%;height:48px;"><?=set_value('p_page_end', $page_end)?></textarea>  
				<?=form_error1($error,'p_page_end', '<font color="red">', '</font>')?>
			</td>
		</tr>
		<tr class="form_line">
			<td class="title">标题规则</td>
			<td class="content">
				<textarea name="p_title_regular" id="title_regular" style="width:80%;height:48px;"><?=set_value('p_title_regular', $title_regular)?></textarea>  
				<?=form_error1($error,'p_title_regular', '<font color="red">', '</font>')?>
			</td>
		</tr>
		<tr class="form_line">
			<td class="title">发表时间规则</td>
			<td class="content">
				<textarea name="p_datetime_regular" id="datetime_regular" style="width:80%;height:48px;"><?=set_value('p_datetime_regular', $datetime_regular)?></textarea>  
				<?=form_error1($error,'p_datetime_regular', '<font color="red">', '</font>')?>
			</td>
		</tr>
		<tr class="form_line">
			<td class="title">来源规则</td>
			<td class="content">
				<textarea name="p_from_regular" id="from_regular" style="width:80%;height:48px;"><?=set_value('p_from_regular', $from_regular)?></textarea>  
				<?=form_error1($error,'p_from_regular', '<font color="red">', '</font>')?>
			</td>
		</tr>
		<tr class="form_line">
			<td class="title">内容规则</td>
			<td class="content">
				<textarea name="p_content_regular" id="content_regular" style="width:80%;height:48px;"><?=set_value('p_content_regular', $content_regular)?></textarea>  
				<?=form_error1($error,'p_content_regular', '<font color="red">', '</font>')?>
			</td>
		</tr>
		<tr class="form_line">
			<td class="title">单页内待采集作者规则</td>
			<td class="content">
				<textarea name="p_author_regular" id="author_regular" style="width:80%;height:48px;"><?=set_value('p_author_regular', $author_regular)?></textarea>  
				<?=form_error1($error,'p_author_regular', '<font color="red">', '</font>')?>
			</td>
		</tr>
		<tr class="form_line">
			<td class="title">插入数据库文章所属分类名</td>
			<td class="content">
				<textarea name="p_page_class" id="page_class" style="width:80%;height:48px;"><?=set_value('p_page_class', $page_class)?></textarea>  
				<?=form_error1($error,'p_page_class', '<font color="red">', '</font>')?>
			</td>
		</tr>
		
		<tr>
			<td class="form_button" colspan="2">
				<input type="submit" value=" 提交  "> 
				<font color="red"></font>
				<input type="button" id="btn_collection" value=" 采集  ">
			</td>
		</tr>
	</tbody></table>
</div>
</td><td>
<div id="right" ></div>
</td></table>
</form> 
</body>